package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.pojo.UserDomain;
import com.example.demo.service.UserService;

/**
 * Created by Administrator on 2017/8/16.
 */
@Controller
//@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	private UserService userService;

	@RequestMapping("{hh}")
	public String hh(@PathVariable("hh") String hh) {
		
		return hh;
	}
//	@RequestMapping("hh")
//	public String hh() {
//		
//		return "2";
//	}

	@RequestMapping("hello")
	@ResponseBody
	public String hello() {
//		System.out.println("hello 世界！");
//		System.out.println("hello 世界！");
//		System.out.println("hello 世界！");
//		System.out.println("hello 世界！");
		return "hello 世界！";
	}
	
	@RequestMapping("hello2")
	@ResponseBody
	public String hello2() {
//		System.out.println("hello 世界！");
//		System.out.println("hello 世界！");
//		System.out.println("hello 世界！");
//		System.out.println("hello 世界！");
		return "hello 世界！";
	}

	@ResponseBody
	@PostMapping("/add")
	public int addUser(UserDomain user) {
		return userService.addUser(user);
	}

	@ResponseBody
	@GetMapping("/all")
	public Object findAllUser(@RequestParam(name = "pageNum", required = false, defaultValue = "1") int pageNum,
			@RequestParam(name = "pageSize", required = false, defaultValue = "3") int pageSize) {
		return userService.findAllUser(pageNum, pageSize);
	}
}
